' ' Optimizing Your AmigaBasic Programs for Speed ' ' Stephen R. Pietrowicz ' ' Listing 2 - Card Shuffling example ' DIM card$(52), Shuffled$(52), Check(52) DIM Spot$(4) Spot$(0) = " of clubs" Spot$(1) = " of spades" Spot$(2) = " of diamonds" Spot$(3) = " of hearts" DATA "ace","two","three","four","five","six","seven" DATA "eight","nine","ten","jack","queen","king" Main: RANDOMIZE TIMER ' ' ShuffleA ' PRINT "Shuffling...." a1$ = TIME$ FOR S = 1 TO 10 RESTORE GOSUB Init FOR I = 1 TO 52 Check(I) = 0 NEXT I FOR I = 1 TO 52 Again: X = INT(RND*52+1) IF (Check(X) = 1) GOTO Again Shuffled$(I) = card$(X) Check(X) = 1 NEXT I NEXT S a2$ = TIME$ PRINT "ShuffleA -- Start: ";a1$;" End ";a2$ ' ' Shuffle B ' PRINT "Shuffling...." b1$ = TIME$ FOR S = 1 TO 10 RESTORE GOSUB Init FOR I = 1 TO 52 X = INT(RND*52+1) SWAP card$(I),card$(X) NEXT I NEXT S b2$ = TIME$ PRINT "ShuffleB -- Start: ";b1$;" End ";b2$ END Init: X = 1 FOR J = 1 TO 13 READ A$ FOR I = 0 TO 3 card$(X) =A$+Spot$(I) X = X + 1 NEXT I NEXT J RETURN